package com.cc.wechat.service;

import org.springframework.stereotype.Service;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Service
public class TokenBlacklistService {
    private final ConcurrentMap<String, Long> blacklist = new ConcurrentHashMap<>();

    /**
     * 将token加入黑名单
     */
    public void addToBlacklist(String token) {
        blacklist.put(token, System.currentTimeMillis());
    }

    /**
     * 检查token是否在黑名单中
     */
    public boolean isBlacklisted(String token) {
        return blacklist.containsKey(token);
    }

    /**
     * 清理过期的黑名单token
     */
    public void cleanupExpiredTokens(long expirationTimeInMillis) {
        long now = System.currentTimeMillis();
        blacklist.entrySet().removeIf(entry -> 
            now - entry.getValue() > expirationTimeInMillis
        );
    }
} 